<!DOCTYPE HTML>
<html lang="en">
<head>
<title>#ErrorStdOut - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The #ErrorStdOut directive sends any syntax error that prevents a script from launching to the standard error stream (stderr) rather than displaying a dialog." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>#ErrorStdOut</h1>

<p>Sends any syntax error that prevents a script from launching to the standard error stream (stderr) rather than displaying a dialog.</p>

<pre class="Syntax"><span class="func">#ErrorStdOut</span> <span class="optional">Encoding</span></pre>

<h2>Parameters</h2>
<dl>
  <dt>Encoding</dt>
  <dd><span class="ver">[v1.1.33+]:</span> An <a href="FileEncoding.htm">encoding string</a> specifying how to encode the output. For example, <code>#ErrorStdOut UTF-8</code> encodes error messages as UTF-8 before sending them to stderr. Whatever program is capturing the output must support UTF-8, and in some cases may need to be configured to expect it. If omitted, it defaults to <code>CP0</code>.</dd>
</dl>

<h2>Remarks</h2>
<p><span class="ver">[AHK_L 42+]:</span> Errors are written to stderr instead of stdout. The command prompt and fancy editors usually display both. This change was undocumented until after <span class="ver">[v1.1.19.01]</span>.</p>
<p>This allows fancy editors such as TextPad, SciTE, Crimson, and EditPlus to jump to the offending line when a syntax error occurs. Since the #ErrorStdOut directive would have to be added to every script, it is usually better to set up your editor to use the <a href="../Scripts.htm#cmd">command line switch</a> <strong>/ErrorStdOut</strong> when launching any AutoHotkey script (see further below for setup instructions).</p>
<p>Because AutoHotkey is not a console program, errors will not appear at the command prompt directly. Instead, such output can be captured via piping or redirection. For example:</p>
<pre class="no-highlight">&quot;C:\Program Files\AutoHotkey\AutoHotkey.exe&quot; /ErrorStdOut &quot;My Script.ahk&quot; <strong>2&gt;&amp;1 |more</strong>
&quot;C:\Program Files\AutoHotkey\AutoHotkey.exe&quot; /ErrorStdOut &quot;My Script.ahk&quot; <strong>2&gt;&quot;Syntax-Error Log.txt&quot;</strong></pre>
<p>You can also pipe the output directly to the clipboard by downloading <a href="https://www.autohotkey.com/misc/cb.zip">cb.zip</a> (4 KB) and then following this example:</p>
<pre class="no-highlight">&quot;C:\Program Files\AutoHotkey\AutoHotkey.exe&quot; /ErrorStdOut &quot;My Script.ahk&quot; <strong>2&gt;&amp;1 |cb.exe</strong></pre>
<p class="note"><strong>Note:</strong> <code>2&gt;&amp;1</code> causes stderr to be redirected to stdout, while <code>2&gt;<i>Filename</i></code> redirects only stderr to a file.</p>

<h2>Instructions for specific editors</h2>
<p><strong>EditPlus</strong>:<br>
From the menu bar, select Tools &gt; Configure User Tools.<br>
Press button: Add Tool &gt; Program<br>
Menu Text: Your choice<br>
Command: C:\Program Files\AutoHotkey\AutoHotkey.exe<br>
Argument: /ErrorStdOut &quot;$(FilePath)&quot;<br>
Initial directory: $(FileDir)<br>
Capture output: Yes</p>
<p><strong>TextPad</strong>:<br>
  From the menu bar, select Configure &gt; Preferences.<br>
  Expand the Tools entry.<br>
Press the Add button and select &quot;Program&quot;.<br>
  Copy and paste (adjust to your path): <em>C:\Windows\System32\cmd.exe</em> -- then press OK.<br>
  Triple-click the newly added item (cmd.exe) in the ListBox and rename it to your choice (e.g. Launch Script).<br>
  Press Apply. <br>
  Select the new item in the tree at the left and enter the following information:<br>
  Command (should already be filled in): cmd.exe (or the full path to it)<br>
  Parameters (adjust to your path, if necessary): /c &quot;&quot;C:\Program Files\AutoHotkey\AutoHotkey.exe&quot; /ErrorStdOut &quot;$File&quot;&quot;<br>
  Initial folder: $FileDir<br>
  Check the following boxes:
  1) Run minimized; 2) Capture output.<br>
  Press OK. The newly added item should now exist in the Tools menu.</p>
<h2>Related</h2>
<p><a href="FileAppend.htm">FileAppend</a> (because it can also send text to stderr or stdout)</p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>#ErrorStdOut</pre>
</div>

</body>
</html>
